function getRandomColor(): [number, number, number] {
  // 返回一个随机的颜色，格式为 [R, G, B]
  return [
    Math.floor(Math.random() * 256),
    Math.floor(Math.random() * 256),
    Math.floor(Math.random() * 256),
  ];
}

function brightness([r, g, b]: [number, number, number]): number {
  // 使用简单的公式计算亮度
  return (r + g + b) / 3;
}

function convertToHex(color: [number, number, number]): string {
  return color
    .map((component) => {
      const hex = component.toString(16);
      return hex.length === 1 ? "0" + hex : hex;
    })
    .join("");
}

export const setBackGroundColor = () => {
  let colorA = getRandomColor();
  let colorB = getRandomColor();

  // 确保第一个颜色比第二个颜色更亮或相同亮度
  if (brightness(colorA) < brightness(colorB)) {
    [colorA, colorB] = [colorB, colorA]; // 交换颜色
  }

  const hexColorA = `#${convertToHex(colorA)}`;
  const hexColorB = `#${convertToHex(colorB)}`;

  document.body.style.background = `linear-gradient(to bottom right, ${hexColorA}, ${hexColorB})`;
  document.documentElement.style.setProperty("--lyricColor", hexColorB);
};
